<div id="userList" style=" height:100%;margin: 0px;padding: 0px;">
    <!--调用子组件-->
    <list-component ref="child"
                    :title="title"
                    :init-url="initUrl"
                    :line-event="event"
                    :watch-child="eventCallBack"
    ></list-component>
</div>

<script>
    $(document).ready(function(){
        //采用vue
        var userList=new Vue({
            el: '#userList',
            data: {
                title:'用户查询',
                initUrl : '/pageInit/getInitListPageDto/UserInfo',
                event : ['角色调整'],
                child : null,
            },
            methods: {
                /**与event数组配合使用 当触发点击事件时回调的方法*/
                eventCallBack: function(item,name) {
                    //alert('回调函数' + name + ' ' + item.id);
                    if ('角色调整' == name ) {
                        this.editUserRole(item);
                    }
                },
                //调整角色权限
                editUserRole:function (item) {
                    //弹框
                    $('#listSelectModal').modal();
                    //调用查询接口
                    this.$send( Vue.prototype.getUrl('/core/config/permission/role/getByUserId?userId='+item.id),null,function(data) {
                        //向外暴露选择列表接口
                        Vue.prototype.$registerSelListComponent('未安排角色列表','['+item.name+']用户角色列表',data.allRoleList,data.myRoleList,function(leftData,rightData){
                            console.log(leftData.length+' '+rightData.length);
                            var permList = new Array();
                            for(var i=0;i<rightData.length;i++){
                                permList.push(rightData[i].id);
                            }
                            var requestObject = {userId:item.id,roleIds:permList};
                            console.log(JSON.stringify(requestObject));
                            //回调函数触发保存
                            Vue.prototype.$send( Vue.prototype.getUrl('/core/config/permission/userRole/saveRoleByUserId'),requestObject,function(data) {
                                alert('保存角色成功');
                            });
                        });
                    });
                },

            },
            mounted: function () {
                this. child = this.$refs['child'] ;
            },
        });

    });
</script>

